<template>
  <el-form :model="form" :rules="rules" ref="formRef">
    <el-form-item label="代理名称" prop="name" :label-width="formLabelWidth">
      <el-input v-model="form.name"></el-input>
    </el-form-item>
    <el-form-item label="序号" prop="sort" :label-width="formLabelWidth">
      <el-input v-model.number="form.sort" placeholder="请填写数字" disabled></el-input>
    </el-form-item>
    <el-form-item label="代理准入标准(单位)" prop="num" :label-width="formLabelWidth">
      <el-input v-model.number="form.num" placeholder="请填写数字"></el-input>
    </el-form-item>
    <el-form-item label="代理返现额度(%)" prop="rebateProportion" :label-width="formLabelWidth">
      <el-input v-model.number="form.rebateProportion" placeholder="请填写数字"></el-input>
    </el-form-item>
    <!-- <el-form-item label="是否自动升级" prop="autoUpdate" :label-width="formLabelWidth">
      <el-select v-model="form.autoUpdate" placeholder="请选择" disabled>
        <el-option label="是" value="1"></el-option>
        <el-option label="否" value="0"></el-option>
      </el-select>
    </el-form-item>-->

    <el-form-item :label-width="formLabelWidth">
      <el-button plain @click="resetForm('formRef')">取消</el-button>
      <el-button type="primary" @click="submitForm('formRef')">确定</el-button>
    </el-form-item>
  </el-form>
</template>
<script>
export default {
  name: "",
  props: ["data"],
  data() {
    return {
      form: {
        name: "",
        sort: "",
        num: "",
        rebateProportion: ""
      },
      formLabelWidth: "150px",
      rules: {
        name: [
          { required: true, message: "请输入姓名", trigger: "blur" },
          { min: 3, max: 5, message: "长度在 3 到 5 个字符", trigger: "blur" }
        ],
        sort: [
          { required: true, message: "请输入序号", trigger: "blur" },
          { type: "number", message: "序号必须为数字值" }
        ],
        num: [
          { required: true, message: "请输入代理准入标准", trigger: "blur" },
          { type: "number", message: "请输入数字" }
        ],
        rebateProportion: [
          { required: true, message: "代理返现额度(%)", trigger: "blur" },
          { type: "number", message: "请输入数字" }
        ]
        // autoUpdate: [
        //   { required: true, message: "代理返现额度(%)", trigger: "blur" }
        // ]
      }
    };
  },
  components: {},
  computed: {},
  beforeMount() {},
  mounted() {
    console.log(this.data);
    this.form = this.data;
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          this.$service
            .updateAgency({
              id: this.data.id,
              name: this.form.name,
              num: this.form.num,
              rebateProportion: this.form.rebateProportion
            })
            .then(res => {
              //console.log(res);
              this.$message({
                message: "修改成功",
                type: "success"
              });
              this.$refs[formName].resetFields();
              this.$emit("submit", false);
            });
        }
      });
    },
     resetForm(formName) {
      this.$emit("cancel", false);
    }
  },
  watch: {}
};
</script>
<style scoped>
</style>
